{% extends "master.html" %}
{% block subtitle %} - 发货管理 - 更新调拨单{% endblock %}

{% block extJS %}
<script src="{{url_for('static', filename='js/customize/tns_add.js')}}" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
    var extPdts = [];
    {% for d,ivt,ivtip in dtldata %}
        extPdts.push('{{d.pdt.no}}');
    {% endfor %}    

    function toSubmit(){
        var msg = [];
        clearMsg();
        $(".err").removeClass("err");
        
        if(!$("#dShopID").val()){
            msg.push('请选择调拨目的地！');
            $("#dShopID").addClass('err');
        }
        if(!$("#awb").val()){
            msg.push('请填写送货单号！');
            $("#awb").addClass('err');
        }
        if($("input[name^='dtl_qty_'],input[name^='olddtl_qty_']").length < 1){
            msg.push('请填写至少一件商品！');
        }
        
        var qtyinput = true;
        var qtyok = true;
        $("input[name^='dtl_qty_'],input[name^='olddtl_qty_']").each(function(){
            var t = $(this);
            var max = parseInt(t.attr('maxqty'));
            
            if(!t.val()){
                var qtyinput = false;
                t.addClass('err');
            }else if(!check_number(t.val())){
                msg.push('请正确填写数量,必须为数字！')   
            }else{
                var q = parseInt(t.val());
                if(q > max){
                    qtyok = false;
                    t.addClass('err');
                }
            }        
        })
        
        if(!qtyinput){
            msg.push('请填写调拨数量！');
        }
        
        if(!qtyok){
            msg.push('请正确填写数量，调拨数量必须少于现存数量！');
        }
        
        if(msg.length>0){
            alertError(msg);
            return false;
        }else{
            $("form").submit();
        }
    }
    
    function toCancel(){
        redirect_alert("{{MSG_LEAVE_WITHOUT_SAVING}}","{{url_for('bpTns.view',action='view',id=obj.id)}}")
    }        

//]]>
</script>
{% endblock %}



{% block main %}
<div class="container">
    <div class="row">
        <ol class="breadcrumb">
          <li><a href="{{url_for('bpRoot.view')}}">主面板</a></li>
          <li><a href="{{url_for('bpTns.view')}}">调拨管理</a></li>
          <li class="active">更新调拨单</li>
        </ol>
    </div>
    <div class="row">
        <div class="btn-toolbar pull-right">
            <div class="btn-group"><button type="submit" class="btn btn-primary" onclick="toSubmit()">{{BTN_SUBMIT}}</button></div>
            <div class="btn-group"><button class="btn btn-inverse" onclick="toCancel()">{{BTN_CANCEL}}</button></div>
        </div>
    </div>
    <div class="row">
        <fieldset>
            <legend>调拨单详情</legend>
            <form class="form-signin" action="{{url_for('bpTns.view',action='update')}}" method="POST"  enctype="multipart/form-data">
                <input type="hidden" name="id" value="{{obj.id}}"/>       
                <div class="col-md-4">
                    <div class="control-group">
                      <label class="control-label" for="no">系统编号</label>
                      <div class="controls"><input name="no" id="no" type="text" value="{{obj.no}}" readonly="true"/></div>
                    </div>
                    <div class="control-group">
                      <label class="control-label" for="source">从本店</label>
                      <div class="controls"><input name="source" id="source" type="text" value="{{ obj.sShop }}" readonly="true"/></div>
                    </div>
                    <div class="control-group">
                      <label class="control-label" for="dShopID">调拨到<span style='color:red'>*</span></label>
                      <div class="controls">
                          {{mymacros.select('dShopID',list=shops,value=obj.dShopID)}}
                      </div>
                    </div>
                   
                    <div class="control-group">
                      <label class="control-label" for="awb">送货单号<span style='color:red'>*</span></label>
                      <div class="controls"><input name="awb" id="awb" type="text" value="{{obj.awb|f}}"/></div>
                    </div>
                </div>
                <div class="col-md-4">   
                    <div class="control-group">
                      <label class="control-label" for="expectDate"><label for="expectDate">预计送达日期</label></label>
                      <div class="controls"><input name="expectDate" id="expectDate" class="datepicker" type="text" value="{{obj.expectDate|fd}}"/></div>
                    </div>
                    <div class="control-group">
                      <label class="control-label" for="createBy"><label for="createBy">经办人</label></label>
                      <div class="controls"><input name="createBy" id="createBy" type="text" readonly="true" value="{{obj.createBy|f}}"/></div>
                    </div>
                    <div class="control-group">
                      <label class="control-label" for="createTime"><label for="createTime">创建日期</label></label>
                      <div class="controls"><input name="createTime" id="createTime" type="text" value="{{obj.createTime|fd}}" class="datepicker"/></div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="control-group">
                      <label class="control-label" for="fee"><label for="fee">费用</label></label>
                      <div class="controls"><input name="fee" id="fee" class="num" type="text" value="{{obj.fee}}"/></div>
                    </div>                    
                    <div class="control-group">
                      <label class="control-label" for="remark">备注</label>
                      <div class="controls"><textarea name="remark" id="remark">{{obj.remark|f}}</textarea></div>
                    </div>
                </div>
               <div class="col-md-12">
                   <label>添加商品</label>
                   <select id="field">
                       <option value="no">商品编号</option>
                       <option value="name">商品名称</option>
                   </select>
                   <input type="text" id="fieldValue" class="input-xxlarge" data-provide="typeahead" autocomplete="off" placeholder="请输入商品相关信息，回车添加商品并清空输入框信息"/>
                   <table class="table table-bordered">
                        <thead>
                            <tr>
                                <td style="width:20px">&nbsp;</td>
                                <td class="col-md-2">商品编号</td>
                                <td>商品名称</td>
                                <td class="col-md-2">商品描述</td>
                                <td class="col-md-2">所在仓位</td>
                                <td class="col-md-1">现存数量</td>
                                <td class="col-md-1">调拨数量</td>
                                <td class="col-md-2">备注</td>
                            </tr>
                        </thead>
                        <tbody id="pdtlist">
                            {% for d,ivt,ivtip in dtldata %}
                                <tr>
                                    <td><a href="#" onclick="rmProduct(this)"><i class="glyphicon glyphicon-remove"></i></a></td>
                                    <td><a href="{{url_for('bpPdt.view',action='view',id=d.pdtID)}}" class="pdtclass">{{d.pdt.no}}</a></td>
                                    <td>{{d.pdt.name}}</td>
                                    <td>{{ivt|f}}</td>
                                    {% if ivtip %}
                                        <td>{{ivt|f}}&nbsp;</td>
                                        <td>{{ivtip.qty}}</td>
                                        <td><input type="text" class="col-md-1 num" name="olddtl_qty_{{d.id}}" value="{{d.qty}}" maxqty="{{ivtip.qty}}"/></td>
                                    {% else %}
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td><input type="text" class="col-md-1 num" name="olddtl_qty_{{d.id}}" value="{{d.qty}}" maxqty="0"/></td>
                                    {% endif %}
                                    <td><textarea name="olddtl_rmk_{{d.id}}">{{d.remark|f}}</textarea></td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </fieldset>
        </form>
    </div>

</div>
{% endblock %}